home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1559 < prev    next >
Encoding:
Text File  |  1996-08-06  |  956 b   |  38 lines

  1. Path: sierra.net!usenet
  2. From: "Tyler G. Colwell" <snowbull@sierra.net>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Dumb Question? about ptr
  5. Date: Thu, 11 Jan 1996 08:40:41 -0800
  6. Organization: Sierra-Net
  7. Message-ID: <30F53D89.3473@sierra.net>
  8. References: <00001a81+00008b8f@msn.com>
  9. NNTP-Posting-Host: 204.94.232.59
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b5 (WinNT; I)
  14.  
  15. You can return the address of a class, only of an object that 
  16. has been declared a member of that class.  Also, my compiler 
  17. (VC++) would only compile this if I placed the declarations 
  18. inside main().  Can anyone tell us why this is necessary?  
  19.  
  20. In other words, try this:
  21.  
  22. #include <iostream.h>
  23.  
  24. class MyStruct {
  25.         public:
  26.         int data;
  27.         int value;
  28. };
  29.  
  30.  
  31. void main() {
  32.     MyStruct *foo;
  33.     MyStruct Record1;
  34.     foo = &Record1;   // <-----Note change here
  35.         foo->data=5;
  36.         cout << foo->data;
  37. };
  38.